#pragma once

#include <xml/node.h>

namespace xml {

class attribute_enumeration {
public:
	virtual ~attribute_enumeration() {}
	virtual void first() = 0;
	virtual string current() = 0;
	virtual void next() = 0;
	virtual bool end() = 0;
};

class node_enumeration {
public:
	virtual ~node_enumeration() {}
	virtual void first() = 0;
	virtual handle current() = 0;
	virtual void next() = 0;
	virtual bool end() = 0;
};

class implementation {
public:
	// handle management
	virtual handle copy(handle h) = 0;
	virtual void release(handle h) = 0;
	virtual bool null(handle h) = 0;
	// tag access
	virtual string get_tag(handle h) = 0;
	// attribute access
	virtual attribute_enumeration * get_attributes(handle h) = 0;
	virtual bool get_attribute(handle h, const string & name, string & value) = 0; ///< return false if no attribute found
	virtual void set_attribute(handle h, const string & name, const string & value) = 0;
	// children access
	virtual node_enumeration * get_children(handle h) = 0;
	virtual node_enumeration * get_children_by_tag(handle h, const string & tag) = 0;
	// creation/deletion
	virtual handle create_child(handle h, const string & tag) = 0;
	virtual void clear(handle h, bool attr, bool children) = 0;	///< clears attributes and/or children
	virtual void erase(handle h) = 0;	///< erases itself
protected:
	const_node create_node(handle h) const
		{ return const_node(const_cast<implementation*>(this), h); }
	node create_node(handle h)
		{ return node(this, h); }
	handle get_handle(const node & n) const
		{ return n._handle; }
};

} //namespace xml
